package stone926.mods.noGlint.mixin;

import net.minecraft.enchantment.*;
import net.minecraft.item.*;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Set;

@Mixin(Item.class)
public class ItemMixin {

  @Inject(method = "hasGlint", at = @At("RETURN"), cancellable = true)
  private void hasGlint(ItemStack stack, CallbackInfoReturnable<Boolean> cir) {
    Set<Enchantment> map = EnchantmentHelper.fromNbt(stack.getEnchantments()).keySet();
    Item item = stack.getItem();
    if (item instanceof ArmorItem) {
      for (Enchantment e : map)
        if (e instanceof ProtectionEnchantment || e instanceof FrostWalkerEnchantment || e instanceof DepthStriderEnchantment) {
          cir.setReturnValue(false); return;
        }
    } else if (item instanceof BowItem) {
      for (Enchantment e : map)
        if (e instanceof MendingEnchantment || e instanceof InfinityEnchantment) {
          cir.setReturnValue(false); return;
        }
    } else if (item instanceof CrossbowItem) {
      for (Enchantment e : map)
        if (e instanceof PiercingEnchantment || e instanceof MultishotEnchantment) {
          cir.setReturnValue(false); return;
        }
    } else if (item instanceof ToolItem) {
      for (Enchantment e : map)
        if (e instanceof DamageEnchantment || e instanceof SilkTouchEnchantment || e.equals(Enchantments.FORTUNE)) {
          cir.setReturnValue(false); return;
        }
    } else if (item instanceof TridentItem) {
      for (Enchantment e : map)
        if (e instanceof RiptideEnchantment || e instanceof ChannelingEnchantment) {
          cir.setReturnValue(false); return;
        }
    }
  }

}
